<?php
require_once 'includes/image_resizer.php'; 
//print_r($_REQUEST);
$smsg="";
if($_SESSION['user_id_sess']=="") {
	echo "<script type='text/javascript'> window.location='index.php?signin&url=post'; </script>";
}
$id = $_REQUEST['editjob'];
@extract($_REQUEST);
if($_POST)
{
	$today=date("Y-m-d G:i:s",time());
	
	$duration=$_REQUEST['post_duration'];
	$bargainDuration = date("Y-m-d G:i:s",time() + ($duration * 24 * 60 * 60));		
	$post_name=$_REQUEST['post_name'];	
	$post_location=$_REQUEST['post_location'];
	$bedroom=$_REQUEST['bedrooms'];
	$bathroom=$_REQUEST['bathrooms'];
	$price=$_REQUEST['price'];
	
	$category=$_REQUEST['post_category'];	
	$post_description=$_REQUEST['post_description'];
	$post_duration=$_REQUEST['post_duration'];	
	$remarks=$_REQUEST['post_remarks'];
	
	
	if($_REQUEST['post_category']=='2'){
	$sqlPost="update tbl_post set post_name='$post_name',
				subcategory_id='$pro_sub_subcategory',				
				post_description='$post_description',
				post_location='$post_location',
				price   = '$jobprice',
				post_company='$compName',
				post_contact='$contact',
				post_phone='$phone',
				post_email='$email',
				post_experience='$experience',
				education='$education',
				post_remarks='$remarks',
				post_duration='$post_duration',			
				posted_by='$userId',
				posted_date='$today' where post_id='".$_POST['pid']."'";
				
		$rstPost=mysql_query($sqlPost) or die(mysql_error());		
	}
	
	if($_REQUEST['post_category']=='3'){
	$sqlPost="update tbl_post set post_name='$post_name',
				subcategory_id='$pro_sub_subcategory',				
				post_description='$post_description',
				post_location='$post_location',
				price   = '$rentprice',
				post_company='$company',
				bedroom='$bedrooms',
				bathroom='$bathrooms',
				post_sqrt='$sqrtfeet',
				post_yearbuild='$yearbuild',
				post_property='$property',
				post_remarks='$remarks',
				post_duration='$post_duration',			
				posted_by='$userId',
				posted_date='$today' where post_id='".$_POST['pid']."'";
				
				
		$rstPost=mysql_query($sqlPost) or die(mysql_error());		
	}		
	if($_REQUEST['post_category']=='4'){
	$sqlPost="update tbl_post set post_name='$post_name',
				subcategory_id='$pro_subcategory',				
				post_description='$post_description',
				post_location='$post_location',
				price   = '$realprice',
				post_company='$company',
				bedroom='$bedrooms',
				bathroom='$bathrooms',
				post_sqrt='$sqrtfeet',
				post_yearbuild='$yearbuild',
				post_property='$property',
				post_remarks='$remarks',
				post_duration='$post_duration',			
				posted_by='$userId',
				posted_date='$today' where post_id='".$_POST['pid']."'";
		$rstPost=mysql_query($sqlPost) or die(mysql_error());		
	}
	if($_REQUEST['post_category']=='5'){
	$sqlPost="update tbl_post set post_name='$post_name',
				subcategory_id='$pro_subcategory',				
				post_description='$post_description',
				post_location='$post_location',
				price   = '$serviceprice',
				post_company='$company',
				post_remarks='$remarks',
				post_duration='$post_duration',			
				posted_by='$userId',
				posted_date='$today' where post_id='".$_POST['pid']."'";
		$rstPost=mysql_query($sqlPost) or die(mysql_error());		
	}
	
	if(mysql_affected_rows()>0) {	
		$smsg="true";
		$postId=mysql_insert_id();	
		$postImage=pathinfo($_FILES["post_image"]["name"]);		
			if(!empty($postImage['extension'])) {			
				if(strtolower($postImage['extension'])=="jpeg" || strtolower($postImage['extension'])=="jpg" || 
					strtolower($postImage['extension'])=="png" || strtolower($postImage['extension'])=="gif") {											
					$orgname=mt_rand();				
					$type=$postImage['extension'];				
					$path="posts/original/".$orgname.$postId.".".$type;					
					$path_thumb="posts/thumb/".$orgname.$postId."_thumb.".$type;					
					$path_medium="posts/medium/".$orgname.$postId."_medium.".$type;									
					move_uploaded_file($_FILES["post_image"]["tmp_name"],$path);				  
					productResize($path, $path_thumb, $path_medium, $type);	
					$imagePath[] = 	$path;	
					$mediumPath[] = $path_medium;	
					$thumbPath[] = 	$path_thumb;	
					$sql_updpro="UPDATE tbl_post set 
								 post_image_thumb='".$path_thumb."',
								 post_image_sample='".$path_medium."',
								 post_image='".$path."'
								 where post_id=$postId";	
					$rst_updpro=mysql_query($sql_updpro) or die(mysql_error());
					if(mysql_affected_rows()==0) { $smsg="false"; }	
				}
			 }		
	}
	else { $smsg="false"; }	
}
//get record
$userId=$_SESSION['user_id_sess'];
$sqlQuery="SELECT * FROM tbl_post where posted_by='$userId' and post_id='".$_REQUEST['postid']."' order by post_id desc";

$resultSetJob=mysql_query($sqlQuery);
$data=@mysql_fetch_object($resultSetJob);
?>
<style type="text/css">
	#sell-form { border:0px solid #CCC; vertical-align:top; padding:10px; float:left; width:93%; margin:2%; }

	#sell-form label{
	float: left;
	width: 130px;
	font-weight: bold;
	}
	
	#sell-form input, select, textarea{	
	width: 280px;
	margin-bottom: 5px;
	font-size:12px;
	}
	
	#sell-form textarea{
	height: 250px;
	width: 450px;
	font-size:12px
	}
	
	#sell-form #submitbutton{
	margin-left: 130px;
	margin-top: 5px;
	width: 90px;
	}
	
	#sell-form br{
	clear: left;
	}

	
</style>
<div id='panel'>
<table width="100%" border="0">
  <tr>
    <td class="contentHeader"><h2>Edit Posts</h2></td>
    <td class="contentHeader" align="right">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">
	
	<table width="100%" align="center"  border="0" cellspacing="0">
      <tr>
	  	<td><?php if($smsg=="true") { echo "<div id='suc-msg'> Posts updated successfully. </div>"; } ?></td>
	  </tr>
      <tr>
        <td height="500">		
		<form name="frmPost" id="frmPost" method="post" action="" enctype="multipart/form-data" onsubmit="funPost();">    
			 
				<div id="sell-form">
									
					
					<?php 					
				
			
			if($id!="") {			
					$qry="SELECT * FROM tbl_category where parent_id='$id'";
					$res=mysql_query($qry);
					if(mysql_num_rows($res) > 0) {			
											
						?>
						<label for="pro_sub_subcategory">Sub Category</label>
						<select name="pro_sub_subcategory" id="pro_sub_subcategory">
							<option value="">..Select subcategory..</option>
							<?php
							while($row = mysql_fetch_assoc($res))
							{	
							if($row['category_id']==$data->subcategory_id)
							{
							$selected=" Selected";
							}			
								echo "<option value='".$row['category_id']."' $selected>".$row['category_name']."</option>";	
								$selected="";				
							}
							?>
						</select><br>						
					<?php
					} else {
						?> 
						<label for="pro_sub_subcategory">Sub Category</label>
						<select name="pro_sub_subcategory" id="pro_sub_subcategory">
							<option value="">..Select sub-subcategory..</option>
						</select><br>
						<?php
					}						
							
				}
				else {
						?> 
						<label for="pro_sub_subcategory">Sub Category</label>
						<select name="pro_sub_subcategory" id="pro_sub_subcategory">
							<option value="">..Select sub-subcategory..</option>
						</select><br>
						<?php
					}							
						
					?>
					<label for="post_name">Post Name</label>
					<input type="text" name="post_name" id="post_name" style="width:450px;" value="<?php echo $data->post_name; ?>"><br>
					
					<label for="post_description">Description</label>
					<textarea name="post_description" id="post_description"><?php echo $data->post_description; ?></textarea><br>					
					
					<label for="post_location">Location</label>
					<input type="text" name="post_location" id="post_location" value="<?php echo $data->post_location; ?>">
					<br>	

					<?php
					

if($id=="2") {	?>		
	
	<label for="price">Job Salary</label>
	<input type="text" name="jobprice" id="jobprice" value="<?php echo $data->price; ?>">
	<input type="hidden" name="hidCatType" id="hidCatType" value="job">
	<br>
    <!-- Codex Technology Add Field -->
    <label for="price">Company Name</label>
	<input type="text" name="compName" id="compName"  value="<?php echo $data->post_company; ?>">
		<br>
    <label for="experience">Experience</label>
	<input type="text" name="experience" id="experience" value="<?php echo $data->post_experience; ?>">
	<br>
    <label for="experience">Education Level</label>
	<input type="text" name="education" id="education" value="<?php echo $data->education; ?>">
	<br>
    <label for="contact">Contact</label>
	<input type="text" name="contact" id="contact" value="<?php echo $data->post_contact; ?>">
	<br>
    <label for="phone">Phone</label>
	<input type="text" name="phone" id="phone" value="<?php echo $data->post_phone; ?>">
	<br>
    <label for="email">Email Address</label>
	<input type="text" name="email" id="email" value="<?php echo $data->post_email; ?>">
	<br>	
    <!-- Codex Technology END -->
<?php							
} else if($id=="3") { ?>
	<label for="bedroom">Bedrooms</label>
	<input type="text" name="bedrooms" id="bedrooms" value="<?php echo $data->bedroom; ?>">
	<input type="hidden" name="hidCatType" id="hidCatType" value="rent">
	<br>
	<label for="bathrooms">Bathrooms</label>
	<input type="text" name="bathrooms" id="bathrooms" value="<?php echo $data->bathroom; ?>">	
	<br>
	<label for="price">Price</label>
	<input type="text" name="rentprice" id="rentprice" value="<?php echo $data->price; ?>">	
	<br>
    <!-- Codex Technology Add Field -->	
    <label for="company">Company</label>
	<input type="text" name="company" id="company" value="<?php echo $data->post_company; ?>">	
	<br>
    <label for="sqrtfeet">SQ FT</label>
	<input type="text" name="sqrtfeet" id="sqrtfeet" value="<?php echo $data->post_sqrt; ?>">	
	<br>
    <label for="yearbuild">Year Build</label>
	<input type="text" name="yearbuild" id="yearbuild" value="<?php echo $data->post_yearbuild; ?>">	
	<br>
    <label for="property">Property Type</label>
	<input type="text" name="property" id="property" value="<?php echo $data->post_property; ?>">	
	<br>
     <!-- Codex Technology END -->		
<?php						
} else if($id=="4") { ?>
<!-- Codex Technology Add Field -->
   <label for="bedroom">Bedrooms</label>
	<input type="text" name="bedrooms" id="bedrooms" value="<?php echo $data->bedroom; ?>">
	<input type="hidden" name="hidCatType" id="hidCatType" value="realstate">
	<br>
	<label for="bathrooms">Bathrooms</label>
	<input type="text" name="bathrooms" id="bathrooms" value="<?php echo $data->bathroom; ?>">	
	<br>
	<label for="price">Price</label>
	<input type="text" name="realprice" id="realprice" value="<?php echo $data->price; ?>">	
	<br>	
    <label for="company">Company</label>
	<input type="text" name="company" id="company" value="<?php echo $data->post_company; ?>">	
   	<br>
    <label for="sqrtfeet">SQ FT</label>
	<input type="text" name="sqrtfeet" id="sqrtfeet" value="<?php echo $data->post_sqrt; ?>" />	
	<br>
    <label for="yearbuild">Year Build</label>
	<input type="text" name="yearbuild" id="yearbuild" value="<?php echo $data->post_yearbuild; ?>">	
	<br>
    <label for="property">Property Type</label>
	<input type="text" name="property" id="property" value="<?php echo $data->post_property; ?>">	
	<br>		
     <!-- Codex Technology END -->
<?php						
} 

else if($id=="5") { ?>
	<label for="price">Price</label>
	<input type="text" name="serviceprice" id="serviceprice" value="<?php echo $data->price; ?>">	
	<input type="hidden" name="hidCatType" id="hidCatType" value="service">
	<br>	
	
    <!-- Codex Technology Add Field -->
    <label for="company">Company</label>
	<input type="text" name="company" id="company" value="<?php echo $data->post_company; ?>">	
    <br>			
     <!-- Codex Technology END -->
<?php
}	else {
	echo "<input type='hidden' name='hidCatType' id='hidCatType'>";
}
?>
					
					<label for="post_image">Post Image</label>
					<input type="file" name="post_image" id="post_image"><br>
					
					<!--<label for="post_video">Post Video</label>
					<input type="file" name="post_video" id="post_video" disabled><br> -->
															
					<label for="post_duration">Duration</label>
					<select name="post_duration" id="post_duration" style="width:84px;">										
						<option value='3' <?php if($data->post_duration==3){?> selected="selected"<?php }?>>3 days</option>
						<option value='5' <?php if($data->post_duration==5){?> selected="selected"<?php }?>>5 days</option>
						<option value='7' <?php if($data->post_duration==7){?> selected="selected"<?php }?>>7 days</option>
						<option value='10' <?php if($data->post_duration==10){?> selected="selected"<?php }?>>10 days</option>						
				  </select>					
					<br>					
					
					<label for="post_remarks">Remarks</label>
					<textarea name="post_remarks" id="post_remarks" style="height:40px; font-size:12px;"><?php echo $data->post_remarks;?></textarea><br>
																				
					<input type="submit" id="submitbutton" name="submitbutton" value="Submit">
					<br>
				<input type="hidden" name="post_category" id="post_category" value="<?php echo $id;?>" />
				<input type="hidden" name="pid" id="post_remarks" value="<?php echo $_GET['postid'];?>" />
				</div><br>
        </form></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>